/**
 * @author Ahammer
 * @date 2009 05
 * @update 2011 01 changed text field format
 */

/*
 * This file is part of Iqm.
 * Copyright (c) 2010-2011 Helmut Ahammer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package opgui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.swing.ButtonGroup;
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.text.InternationalFormatter;

import main.IqmTools;
import main.Look;
import main.Manager;
import main.Tank;


public class IqmCalcValueGUI  extends IqmOperatorJFrame
							  implements IqmOperatorGUIBuilder, ActionListener, AdjustmentListener, PropertyChangeListener {

	private  ParameterBlockJAI    pbJAI         = null;  //  @jve:decl-index=0:
	//public  ImgProcFuncJFrame   opGUIFrame = null;
	//private  IqmCalcValueGUI 	  opGUIFrame = null;  //actionPerformed events werden in dieser Klasse abgehandelt
	
		
	private JRadioButtonMenuItem buttAdd			= null;
	private JRadioButtonMenuItem buttSubtr			= null;
	private JRadioButtonMenuItem buttMult			= null;
	private JRadioButtonMenuItem buttDiv			= null;
	private JRadioButtonMenuItem buttSubtrFromConst	= null;
	private JRadioButtonMenuItem buttDivIntoConst	= null;

	private JRadioButtonMenuItem buttAND			= null;
	private JRadioButtonMenuItem buttOR		    	= null;
	private JRadioButtonMenuItem buttXOR			= null;
	private JRadioButtonMenuItem buttCalcHidden  	= null;
	private JToolBar 			  jToolBarCalc	    = null;
	private ButtonGroup 		  buttGroupCalc		= null;
	
	private JPanel 				 jPanelResultOptions 	= null;
	private JLabel 				 jLabelResultOptions	= null;
	private JToolBar 			 jToolBarResultOptions	= null;
	private ButtonGroup 		 buttGroupResultOptions	= null;
	private JRadioButtonMenuItem buttResultOptionsHidden= null;
	private JRadioButtonMenuItem buttClamp				= null;
	private JRadioButtonMenuItem buttNormalize			= null;
	private JRadioButtonMenuItem buttActual				= null;

	private JPanel 				 	jPanelValue					= null;	
	private JLabel				 	jLabelValue					= null;
	private JFormattedTextField 	jFormattedTextFieldValue 	= null;
	
	/**
	 * constructor
	 */
	public IqmCalcValueGUI() {

	}

	
	/**
	 * This method sets all  variables to null
	 */
	private void resetVariables(){
		pbJAI         = null; 
		//opGUIFrame = null; 
		
		//jToolBarRGB  = null;

	}
	/**
	 * This method sets all parameters to null
	 */
	private void resetParameters(){
		//butt       = null;
		//butt       = null;
	}

	/**
	 * This method sets the current parameter block to the argument
	 * @param ParameterBlockJAI pbJAI
	 */
	@Override
	public void setParameterBlock(ParameterBlockJAI arg){
		pbJAI = arg;
		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	/**
	 * This method sets the current parameter block
	 * The individual values of the GUI  current ParameterBlock
	 *
	 */
	@Override
	public void setParameterBlock(){

		if (buttAdd.isSelected())     		 pbJAI.setParameter("Calc", 0);
		if (buttSubtr.isSelected())  		 pbJAI.setParameter("Calc", 1);
		if (buttMult.isSelected())			 pbJAI.setParameter("Calc", 2);
		if (buttDiv.isSelected())   		 pbJAI.setParameter("Calc", 3);
		if (buttSubtrFromConst.isSelected()) pbJAI.setParameter("Calc", 4);
		if (buttDivIntoConst.isSelected())   pbJAI.setParameter("Calc", 5);
		if (buttAND.isSelected())			 pbJAI.setParameter("Calc", 6);
		if (buttOR.isSelected())     		 pbJAI.setParameter("Calc", 7);
		if (buttXOR.isSelected())     		 pbJAI.setParameter("Calc", 8);
	
		pbJAI.setParameter("Value", ((Number)jFormattedTextFieldValue.getValue()).doubleValue());
		
		if (buttClamp.isSelected()) 	pbJAI.setParameter("ResultOptions", 0);
		if (buttNormalize.isSelected()) pbJAI.setParameter("ResultOptions", 1);
		if (buttActual.isSelected()) 	pbJAI.setParameter("ResultOptions", 2);

		IqmTools.setCurrParameterBlockJAI(pbJAI);	
	}
	
	/**
	 * This method sets the current parameter values
	 *
	 */
	@Override
	public void setParameterValues(){
		int idx = IqmTools.getCurrManagerImgIndex();
	    PlanarImage pi = Tank.getCurrentTankImageAt(idx); 
	       if (pi == null){
	    	   System.out.println("IqmCalcValueGUI: Current image not defined");
	    	   return;
	       }
//	    int pixelSize = pi.getColorModel().getPixelSize();
//      int numBands  = pi.getNumBands(); 
//      String type = IqmTools.getCurrImgTyp(pixelSize, numBands);
        //-------------------------------------------------

        if (pbJAI.getIntParameter("Calc") == 0)     buttAdd.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 1)     buttSubtr.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 2)     buttMult.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 3)     buttDiv.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 4)     buttSubtrFromConst.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 5)     buttDivIntoConst.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 6)     buttAND.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 7)     buttOR.setSelected(true);
        if (pbJAI.getIntParameter("Calc") == 8)     buttXOR.setSelected(true);
        
        jFormattedTextFieldValue.removePropertyChangeListener("value", this);
		jFormattedTextFieldValue.setValue(pbJAI.getDoubleParameter("Value"));
        jFormattedTextFieldValue.addPropertyChangeListener("value", this);
        
		if (pbJAI.getIntParameter("ResultOptions") == 0)     buttClamp.setSelected(true);
		if (pbJAI.getIntParameter("ResultOptions") == 1)     buttNormalize.setSelected(true);
		if (pbJAI.getIntParameter("ResultOptions") == 2)     buttActual.setSelected(true);
	}

	/**
	 * This method creates and shows the GUI
	 */
	@Override
	public void createIqmOperatorGUI() {
		//System.out.println("IqmCalcValue: createAndShowGUI invoked");
		//opGUIFrame = new IqmCalcValueGUI();      //actionPerforemd events werden in dieser Klasse abgehandelt
		//opGUIFrame.getJContentPane();
		this.initialize(); //Aufruf von ImgProcFuncJFrame
		this.setTitle("CalcValue");
		//PlanarImage pi = Tank.getCurrentTankImageAt(IqmTools.getCurrManagerImgIndex());
		//Dimension dim = this.getSize();
		//this.setSize(dim.width, dim.height + 230);
		//this.setPreferredSize(new Dimension(800, 600));

		this.getJContentPane().add(getJToolBarCalc(),        getGridBagConstraintsCalc());
		this.getJContentPane().add(getJPanelValue(),         getGridBagConstraintsValue());
		this.getJContentPane().add(getJPanelResultOptions(), getGridBagConstraintsResultOptions());
	
		this.pack();
		//this.repaint();
		if (pbJAI == null) pbJAI = new ParameterBlockJAI("IqmCalcValue");  //nur wenn das erste mal aufgerufen
		//pbJAI = new ParameterBlockJAI("iqmthreshold"); //immer der default Block
		IqmTools.setCurrParameterBlockJAI(pbJAI);
		this.setParameterValues();
	}

	private  GridBagConstraints getGridBagConstraintsCalc(){
		GridBagConstraints gridBagConstraintsCalc = new GridBagConstraints();
		gridBagConstraintsCalc.gridx = 1;
		gridBagConstraintsCalc.gridy = 7;
		gridBagConstraintsCalc.gridwidth = 3;
		gridBagConstraintsCalc.insets = new Insets(15,0,0,0); //top left bottom right

		//gridBagConstraintsCalc.anchor = GridBagConstraints.LINE_START;
		//gridBagConstraintsCalc.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsCalc;
	}
	private  GridBagConstraints getGridBagConstraintsValue(){
		GridBagConstraints gridBagConstraintsValue = new GridBagConstraints();
		gridBagConstraintsValue.gridx = 1;
		gridBagConstraintsValue.gridy = 8;
		gridBagConstraintsValue.gridwidth = 3;//?
		gridBagConstraintsValue.insets = new Insets(10,0,0,0); //top left bottom right
		//gridBagConstraintsValue.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsValue;
	}
	private  GridBagConstraints getGridBagConstraintsResultOptions(){
		GridBagConstraints gridBagConstraintsResultOptions = new GridBagConstraints();
		gridBagConstraintsResultOptions.gridx = 1;
		gridBagConstraintsResultOptions.gridy = 9;
		gridBagConstraintsResultOptions.gridwidth = 3;//?
		gridBagConstraintsResultOptions.insets = new Insets(10,0,20,0); //top left bottom right
		//gridBagConstraintsResultOptions.fill = GridBagConstraints.BOTH;
		return gridBagConstraintsResultOptions;
	}


	//------------------------------------------------------------------------------------------------------------------
	/**
	 * This method closes and destroys the GUI
	 * 
	 * @return void
	 */
//	public void destroyGUI() {
//		if (this != null){
//					
//			//this.closeAndDestroyGUI();
//			//resetVariables();
//			//folgendes geht auch!?
//			this.setVisible(false);
//			this.dispose();
//			//this = null;
//		}
//	}
	/**
	 * This method updates the GUI
	 * This method overrides IqmOperatorJFrame
	 */
	@Override
	public void updateIqmOperatorGUI(){
	
	}

    //------------------------------------------------------------------------------------
	/**
	 * This method initializes the Option: Add
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonAdd() {
		if (buttAdd == null) {
			buttAdd  = new JRadioButtonMenuItem();
			buttAdd.setText("Image  +  c");
			buttAdd.setToolTipText("adds constant to image");
			buttAdd.addActionListener(this);
			buttAdd.setActionCommand("parameter");
		}
		return buttAdd;
	}
	/**
	 * This method initializes the Option: Subtr
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonSubtr() {
		if (buttSubtr == null) {
			buttSubtr  = new JRadioButtonMenuItem();
			buttSubtr.setText("Image  -  c");
			buttSubtr.setToolTipText("subtracts constant from image");
			buttSubtr.addActionListener(this);
			buttSubtr.setActionCommand("parameter");
		}
		return buttSubtr;
	}
	/**
	 * This method initializes the Option: Mult
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonMult() {
		if (buttMult == null) {
			buttMult  = new JRadioButtonMenuItem();
			buttMult.setText("Image  X  c");
			buttMult.setToolTipText("multiply image by constant");
			buttMult.addActionListener(this);
			buttMult.setActionCommand("parameter");
		}
		return buttMult;
	}
	/**
	 * This method initializes the Option: Div
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonDiv() {
		if (buttDiv == null) {
			buttDiv  = new JRadioButtonMenuItem();
			buttDiv.setText("Image  /  c");
			buttDiv.setToolTipText("divide image by constant");
			buttDiv.addActionListener(this);
			buttDiv.setActionCommand("parameter");
		}
		return buttDiv;
	}
	/**
	 * This method initializes the Option: SubtrFromConst
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonSubtrFromConst() {
		if (buttSubtrFromConst == null) {
			buttSubtrFromConst  = new JRadioButtonMenuItem();
			buttSubtrFromConst.setText("c  -  Image");
			buttSubtrFromConst.setToolTipText("subtracts image from constant");
			buttSubtrFromConst.addActionListener(this);
			buttSubtrFromConst.setActionCommand("parameter");
		}
		return buttSubtrFromConst;
	}


	/**
	 * This method initializes the Option: DivIntoConst
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonDivIntoConst() {
		if (buttDivIntoConst == null) {
			buttDivIntoConst  = new JRadioButtonMenuItem();
			buttDivIntoConst.setText("c  /  Image");
			buttDivIntoConst.setToolTipText("divide constant by image");
			buttDivIntoConst.addActionListener(this);
			buttDivIntoConst.setActionCommand("parameter");
		}
		return buttDivIntoConst;
	}


	/**
	 * This method initializes the Option: AND
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonAND() {
		if (buttAND == null) {
			buttAND  = new JRadioButtonMenuItem();
			buttAND.setText("Image AND c");
			buttAND.setToolTipText("bitwise logical AND");
			buttAND.addActionListener(this);
			buttAND.setActionCommand("parameter");
			buttAND.setEnabled(true);
		}
		return buttAND;
	}
	/**
	 * This method initializes the Option: OR
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonOR() {
		if (buttOR == null) {
			buttOR  = new JRadioButtonMenuItem();
			buttOR.setText("Image  OR  c");
			buttOR.setToolTipText("bitwise logical OR");
			buttOR.addActionListener(this);
			buttOR.setActionCommand("parameter");
			buttOR.setEnabled(true);
		}
		return buttOR;
	}
	/**
	 * This method initializes the Option: XOR
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonXOR() {
		if (buttXOR == null) {
			buttXOR  = new JRadioButtonMenuItem();
			buttXOR.setText("Image XOR c");
			buttXOR.setToolTipText("bitwise logical XOR");
			buttXOR.addActionListener(this);
			buttXOR.setActionCommand("parameter");
			buttXOR.setEnabled(true);
		}
		return buttXOR;
	}
	/**
	 * This method initializes the hidden Button option	
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private JRadioButtonMenuItem getJRadioButtonCalcHidden() {
		//if (buttCalcHidden == null) {
			buttCalcHidden  = new JRadioButtonMenuItem();
			buttCalcHidden.setText("Hidden");
			buttCalcHidden.setVisible(false);
		//}
		return buttCalcHidden;
	}
	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private JToolBar getJToolBarCalc() {
//		if (jToolBarCalc == null) {
			jToolBarCalc = new JToolBar("Calc");
			jToolBarCalc.setOrientation(1); //Vertical orientation
			jToolBarCalc.add(getJRadioButtonAdd());			
			jToolBarCalc.add(getJRadioButtonSubtr());			
			jToolBarCalc.add(getJRadioButtonMult());			
			jToolBarCalc.add(getJRadioButtonDiv());
			jToolBarCalc.add(getJRadioButtonSubtrFromConst());			
			jToolBarCalc.add(getJRadioButtonDivIntoConst());
			jToolBarCalc.add(getJRadioButtonAND());			
			jToolBarCalc.add(getJRadioButtonOR());
			jToolBarCalc.add(getJRadioButtonXOR());
			jToolBarCalc.add(getJRadioButtonCalcHidden());

			//jToolBarCalc.addSeparator();
			this.setButtonGroupCalc();	//Gruppieren der JRadioButtons
//		}
		return jToolBarCalc;
	}
	private void setButtonGroupCalc() {
		//if (ButtonGroup buttGroupCalc == null) {
			buttGroupCalc = new ButtonGroup();
			buttGroupCalc.add(buttAdd);
			buttGroupCalc.add(buttSubtr);
			buttGroupCalc.add(buttMult);
			buttGroupCalc.add(buttDiv);
			buttGroupCalc.add(buttSubtrFromConst);
			buttGroupCalc.add(buttDivIntoConst);
			buttGroupCalc.add(buttAND);
			buttGroupCalc.add(buttOR);
			buttGroupCalc.add(buttXOR);
			buttGroupCalc.add(buttCalcHidden);		
	}
	//------------------------------------------------------------------------------------
	class FloatNumberVerifier extends InputVerifier {
		@Override
		public boolean verify(JComponent input) {
		   JFormattedTextField ftf = (JFormattedTextField)input;
		   JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
		   if (formatter != null) {
		      String text = ftf.getText();
		  	  try {
				   text = text.replace(",", ".");
					Float.valueOf(text);
					return true;
			  } catch (NumberFormatException e) {
					return false;
			  }	 
		   }
		   return true;
		}
//		public boolean shouldYieldFocus(JComponent input) {
//			System.out.println("NumberVerifier  shouldYieldFocus");
//
//	          return verify(input);
//	    }
	}
	/**
	 * This method initializes jJPanelValue	
	 * 	
	 * @return javax.swing.JPanel
	 */
	private JPanel getJPanelValue() {
		if (jPanelValue == null) {
			jPanelValue = new JPanel();
			jPanelValue.setLayout(new BorderLayout());
			//jPanelValue.setPreferredSize(new Dimension(250,18));					
			jLabelValue = new JLabel("c: ");
			jLabelValue.setPreferredSize(new Dimension(20,18));
			jFormattedTextFieldValue = new JFormattedTextField(NumberFormat.getNumberInstance());
			jFormattedTextFieldValue.setPreferredSize(new Dimension(100,18));
			jFormattedTextFieldValue.addPropertyChangeListener("value", this);
		
//			jFormattedTextFieldValue.setInputVerifier(new FloatNumberVerifier());	
			InternationalFormatter intFormatter = (InternationalFormatter)jFormattedTextFieldValue.getFormatter() ;
			DecimalFormat decimalFormat = (DecimalFormat)intFormatter.getFormat() ;
			decimalFormat.applyPattern("#0.000");  //decimalFormat.applyPattern("#,##0.0")  ;
			
			//jFormattedTextFieldValue.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);	
			jFormattedTextFieldValue.setColumns(5);
			jPanelValue.add(jLabelValue, 			  BorderLayout.WEST);
			jPanelValue.add(jFormattedTextFieldValue, BorderLayout.CENTER);	
		
		}
		return jPanelValue;
	}
	
	//------------------------------------------------------------------------------------	
	/**
	 * This method initializes the Option: Clamp
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonClamp() {
		if (buttClamp == null) {
			buttClamp  = new JRadioButtonMenuItem();
			buttClamp.setText("Clamp");
			buttClamp.setToolTipText("clamps result to byte");
			buttClamp.addActionListener(this);
			buttClamp.setActionCommand("parameter");
		}
		return buttClamp;
	}
	/**
	 * This method initializes the Option: Normalize
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonNormalize() {
		if (buttNormalize == null) {
			buttNormalize  = new JRadioButtonMenuItem();
			buttNormalize.setText("Normalize");
			buttNormalize.setPreferredSize(new Dimension(90,10));
			buttNormalize.setToolTipText("normalize result to byte");
			buttNormalize.addActionListener(this);
			buttNormalize.setActionCommand("parameter");
		}
		return buttNormalize;
	}
	/**
	 * This method initializes the Option: Actual
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonActual() {
		if (buttActual == null) {
			buttActual  = new JRadioButtonMenuItem();
			buttActual.setText("Actual");
			buttActual.setPreferredSize(new Dimension(85,10));
			buttActual.setToolTipText("does nothing with result");
			buttActual.addActionListener(this);
			buttActual.setActionCommand("parameter");
			//buttActual.setEnabled(false);
		}
		return buttActual;
	}
	/**
	 * This method initializes the Option: Hidden
	 * 	
	 * @return javax.swing.JRadioButtonMenuItem	
	 */
	private  JRadioButtonMenuItem getJRadioButtonResultOptionsHidden() {
		if (buttResultOptionsHidden == null) {
			buttResultOptionsHidden  = new JRadioButtonMenuItem();
			buttResultOptionsHidden.setText("ResultOptionsHidden");
			buttResultOptionsHidden.setVisible(false);	
		}
		return buttResultOptionsHidden;
	}

	/**
	 * This method initializes jJToolBarBar	
	 * 	
	 * @return javax.swing.JToolBar	
	 */
	private   JToolBar getJToolBarResultOptions() {
//		if (jToolBarResultOptions == null) {
			jToolBarResultOptions = new JToolBar("ResultOptions");
			jToolBarResultOptions.setOrientation(0); //Horizontal orientation
			jToolBarResultOptions.add(getJRadioButtonClamp());			
			jToolBarResultOptions.add(getJRadioButtonNormalize());			
			jToolBarResultOptions.add(getJRadioButtonActual());			
			jToolBarResultOptions.add(getJRadioButtonResultOptionsHidden());

			//jToolBarResultOptions.addSeparator();
			this.setButtonGroupResultOptions();	//Gruppieren der JRadioButtons
//		}
		return jToolBarResultOptions;
	}
	private  void setButtonGroupResultOptions() {
		//if (ButtonGroup buttGroupResultOptions == null) {
			buttGroupResultOptions = new ButtonGroup();
			buttGroupResultOptions.add(buttClamp);			
			buttGroupResultOptions.add(buttNormalize);
			buttGroupResultOptions.add(buttActual);
			buttGroupResultOptions.add(buttResultOptionsHidden);	
	}
	
	/**
	 * This method initializes jPanelResultOptions	
	 * @return javax.swing.JPanel	
	 */
	private  JPanel getJPanelResultOptions() {
		if (jPanelResultOptions == null) {
			jPanelResultOptions = new JPanel();	
			jPanelResultOptions.setLayout(new BorderLayout());
			jPanelResultOptions.setPreferredSize(new Dimension(290, 20));					
			jLabelResultOptions = new JLabel("Result: ");
			//jLabelResultOptions.setPreferredSize(new Dimension(60,10));
			jPanelResultOptions.add(jLabelResultOptions, BorderLayout.WEST);
			jPanelResultOptions.add(getJToolBarResultOptions(), BorderLayout.CENTER);		
		}
		return jPanelResultOptions	;
	}
	
	//--------------------------------------------------------------------------------------------
	public void actionPerformed(ActionEvent e) {
		//System.out.println("IqmCalcValueGUI: event e: " +e.getActionCommand());
		if ("reset".equals(e.getActionCommand())) {
			ParameterBlockJAI pbJAI = new ParameterBlockJAI("IqmCalcValue".toLowerCase());
			IqmTools.setCurrParameterBlockJAI(pbJAI);
			this.setParameterBlock(pbJAI);
			//this.setParameterValues();
			this.updateIqmOperatorGUI();  //if necessary here or some lines above
			this.reset();
		}
		if ("parameter".equals(e.getActionCommand())) {
			if (e.getSource() == buttNormalize){

			}
			if (e.getSource() == buttClamp){
				
			}
			if (e.getSource() == buttActual){
				
			}
			this.setParameterBlock();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
		}
	
	
		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}

	}


	@Override
	public void adjustmentValueChanged(AdjustmentEvent e) {
		Object obE = e.getSource();
	
		this.setParameterBlock();
		this.updateIqmOperatorGUI();  //if necessary here or some lines above
		
		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}
	}
	@Override
	public void propertyChange(PropertyChangeEvent e) {
		if (jFormattedTextFieldValue == e.getSource()) {
			//System.out.println("IqmCalcValueGUI: JFormattedTextField, PropertyChangeEvent");
			this.setParameterBlock();
			//this.updateIqmOperatorGUI();  //if necessary here or some lines above
		}
		//preview if selected
		if (this.isAutoPreviewSelected()){
			this.showPreview();
		}
		
	}
	//-------------------------------------------------------------------------------------------------
	public static void main() {

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				IqmCalcValueGUI gui = new IqmCalcValueGUI();
				gui.createIqmOperatorGUI();

			}
		});
	}






	
}//END
